package pers.zcr.meringue.monolithic.system.captcha.command;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.stereotype.Component;
import pers.zcr.meringue.monolithic.system.captcha.dto.vo.CaptchaVo;
import pers.zcr.meringue.monolithic.system.captcha.gateway.ICaptchaGateway;
import pers.zcr.meringue.monolithic.system.captcha.model.Captcha;

@Component
public class CaptchaGeneratorCmdExe {
    private final ICaptchaGateway captchaGateway;

    public CaptchaGeneratorCmdExe(ICaptchaGateway captchaGateway) {
        this.captchaGateway = captchaGateway;
    }

    public CaptchaVo execute() {
        Captcha captcha = captchaGateway.generateCode();
        return convert(captcha);
    }

    private CaptchaVo convert(Captcha captcha) {
        return BeanUtil.copyProperties(captcha, CaptchaVo.class);
    }
}
